package com.monster.servlet.home;

import com.alibaba.fastjson.JSON;
import com.monster.pojo.Singer;
import com.monster.service.ListServiceImpl;
import com.monster.service.SingerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/home/singer")
public class SingerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String fid = request.getParameter("fid");

        String id = request.getParameter("id");
        String mid = request.getParameter("mid");
        String mmid = request.getParameter("mmid");
        int page = Integer.parseInt(request.getParameter("page"));

        SingerService singerService = new ListServiceImpl();
        ArrayList<Singer> list =singerService.getSingersByOption(fid,id,mid,mmid,page);
        String listJSON = JSON.toJSONString(list);
        PrintWriter out = response.getWriter();
        out.println(listJSON);
        out.flush();
        out.close();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    }
}
